﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Algorithm.Middle_12_IntToRoman
{
    class MainProject
    {
        static void Main(string[] args)
        {
            Console.WriteLine(IntToRoman(3));
            Console.ReadKey();
        }
        public static string IntToRoman(int num)
        {
            Dictionary<int, string> dic = new Dictionary<int, string>()
            {
                {1,"I"},{2,"II"},{3,"III"},{5,"V"},{6,"VI"},{7,"VII"},{8,"VIII"},{10,"X"},{20,"XX"},{30,"XXX"},{60,"LX"},{70,"LXX"},{80,"LXXX"},{50,"L"},{100,"C"},{200,"CC"},{300,"CCC"},{500,"D"},{600,"DC"},{700,"DCC"},{800,"DCCC"},{1000,"M"},
                {4,"IV"}, {9,"IX"}, {40,"XL"}, {90,"XC"}, {400,"CD"}, {900,"CM"}
            };
            string res = string.Empty;
            int thousand = (num / 1000);
            int hundred = ((num / 100) % 10) * 100;
            int ten = ((num / 10) % 10) * 10;
            int individual = num % 10;
            if (thousand != 0) for (int i = 0; i < thousand; i++) res += "M";

            if (dic.ContainsKey(hundred)) res += dic[hundred];
            if (dic.ContainsKey(ten)) res += dic[ten];
            if (dic.ContainsKey(individual)) res += dic[individual];
            return res;
        }
    }
}
